#include "../Worker.h"
#include "WorkerOwnedStates.h"
#include "StateFunctions.h"

#include <iostream>

using namespace std;

//------------------------------------------------------------------------
//
//		WaitA
//
//------------------------------------------------------------------------

WaitW* WaitW::Instance() {
	static WaitW instance;

	return &instance;
}

void WaitW::Enter(Worker* worker) {
	cout << "ENTER WaitW" << endl;
	moveEntityMapCell(worker, worker->getPosIndex());
}

void WaitW::Execute(Worker* worker) {
	//cout << "EXECUTE WaitA" << endl;
	if(!worker->getPath()->empty())
		worker->getStateMachine()->ChangeState(MoveW::Instance());
}

void WaitW::Exit(Worker* worker) {
	cout << "EXIT WaitW" << endl;
}

//------------------------------------------------------------------------
//
//		MoveA
//
//------------------------------------------------------------------------

MoveW* MoveW::Instance() {
	static MoveW instance;

	return &instance;
}

void MoveW::Enter(Worker* worker) {
	cout << "ENTER MoveA" << endl;
	//if no path
	if(worker->getPath()->empty())
		worker->getStateMachine()->ChangeState(WaitW::Instance());
	
	worker->setCurrentDestination(worker->getPath()->front());
	worker->getPath()->pop_front();
}

void MoveW::Execute(Worker* worker) {
	//cout << "EXECUTE MoveA" << endl;
	//If no path
	if(worker->getPath()->empty() && worker->hasArrived()) {
		worker->getStateMachine()->ChangeState(WaitW::Instance());
		return;
	}

	moveUnit(worker);
}

void MoveW::Exit(Worker* worker) {
	cout << "EXIT MoveA" << endl;
}